package com.userdetials;

import com.config.ReadData;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;

import static org.junit.Assert.assertEquals;

/**
 * @author lk
 * @date 2020/6/26 0026 15:24
 * @description:
 */
@RunWith(Parameterized.class)
public class TestEditEmail {

    private static WebDriver d;
    private String username;
    private String password;
    private String email;
    private String result;

    public TestEditEmail(String username, String password, String email, String result) {
        this.username = username;
        this.password = password;
        this.email = email;
        this.result = result;
    }

    @Before
    public void setUp() throws Exception {
        System.setProperty("webdriver.gecko.driver", "F:\\python\\geckodriver.exe");
        d = new FirefoxDriver();

    }

    @Parameterized.Parameters
    public static Collection<String[]> perpareData() throws IOException {
        ArrayList<String[]> params = new ArrayList<>();
        ReadData rd = new ReadData("src/com/config/editemail.csv");
        params.addAll(rd.readcsvData(4));
        return params;
    }

    /**
     * 测试修改邮箱
     */
    @Test
    public void testEditEmail() throws InterruptedException {
        d.get("http://127.0.0.1:8080/login.jsp");
        d.findElement(By.id("username")).sendKeys(username);
        d.findElement(By.id("password")).sendKeys(password);
        d.findElement(By.id("logsub")).click();
        d.findElement(By.xpath("/html/body/h2[2]/a")).click();
        d.findElement(By.xpath("/html/body/center/table/tbody/tr[4]/td[2]/a")).click();
        d.findElement(By.id("email")).sendKeys(email);
        d.findElement(By.id("ediemlsub")).click();
        String a=null;
        try{
            a = d.findElement(By.id("wel_edit_msg")).getText().trim();
        }catch (Exception e){
            e.printStackTrace();
            a="修改成功";
        }
        assertEquals(a,result);

    }


    @After
    public void tearDown() throws Exception {
        d.quit();
    }


}
